<template>
  <el-row>
    <el-col :span="8">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>资源树</span>
        </div>
        <el-tree :data="treeData" :props="defaultProps" @node-click="treeClick"></el-tree>
      </el-card>
    </el-col>
    <el-col :span="16">
      <ViewResource :code="code"></ViewResource>
    </el-col>
  </el-row>
</template>
<script>
import { mapActions } from 'vuex'
import ViewResource from '@/views/system/resource/ViewResource'
export default {
  name: 'Resource',
  components: { ViewResource },
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      treeData: [],
      code: ''
    }
  },
  methods: {
    ...mapActions(['GetMenuTree']),
    treeClick(data) {
      this.code = data.code
    },
    search() {
      this.GetMenuTree().then(res => {
        if (res) {
          this.treeData = res
        }
      }).catch(() => {
      })
    }
  },
  mounted() {
    this.search()
  }
}
</script>
